********************************************************************************
** 	TITLE:		us1996_anes_contact_networks                                  ** 	
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       nes96                                                         **
**  DATE:	    October 2022 						                          **	
**	VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "us1996_anes_contact_networks", replace

* Open the dataset

use "nes96.dta", clear

* Generate variable for interview year

gen inty = 1996


**************************
** STATE-LEVEL OUTCOMES **
**************************

* Note: 1 = Democrat, 2 = Republican

gen statewinner = .

replace statewinner = 2 if V967000B == 1
replace statewinner = 2 if V967000B == 2
replace statewinner = 1 if V967000B == 4
replace statewinner = 1 if V967000B == 5
replace statewinner = 1 if V967000B == 6
replace statewinner = 2 if V967000B == 8
replace statewinner = 1 if V967000B == 9
replace statewinner = 1 if V967000B == 10
replace statewinner = 1 if V967000B == 11
replace statewinner = 1 if V967000B == 12
replace statewinner = 2 if V967000B == 13
replace statewinner = 1 if V967000B == 15
replace statewinner = 2 if V967000B == 16
replace statewinner = 1 if V967000B == 17
replace statewinner = 2 if V967000B == 18
replace statewinner = 1 if V967000B == 19
replace statewinner = 2 if V967000B == 20
replace statewinner = 1 if V967000B == 21
replace statewinner = 1 if V967000B == 22
replace statewinner = 1 if V967000B == 23
replace statewinner = 1 if V967000B == 24
replace statewinner = 1 if V967000B == 25
replace statewinner = 1 if V967000B == 26
replace statewinner = 1 if V967000B == 27
replace statewinner = 2 if V967000B == 28
replace statewinner = 1 if V967000B == 29
replace statewinner = 2 if V967000B == 30
replace statewinner = 2 if V967000B == 31
replace statewinner = 1 if V967000B == 32
replace statewinner = 1 if V967000B == 33
replace statewinner = 1 if V967000B == 34
replace statewinner = 1 if V967000B == 35
replace statewinner = 1 if V967000B == 36
replace statewinner = 2 if V967000B == 37
replace statewinner = 2 if V967000B == 38
replace statewinner = 1 if V967000B == 39
replace statewinner = 2 if V967000B == 40
replace statewinner = 1 if V967000B == 41
replace statewinner = 1 if V967000B == 42
replace statewinner = 1 if V967000B == 44
replace statewinner = 2 if V967000B == 45
replace statewinner = 2 if V967000B == 46
replace statewinner = 1 if V967000B == 47
replace statewinner = 2 if V967000B == 48
replace statewinner = 2 if V967000B == 49
replace statewinner = 1 if V967000B == 50
replace statewinner = 2 if V967000B == 51
replace statewinner = 1 if V967000B == 53
replace statewinner = 1 if V967000B == 54
replace statewinner = 1 if V967000B == 55
replace statewinner = 2 if V967000B == 56


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by state (absolute difference between Democratic and Republican candidates)

gen margin = .

replace margin = 6.965755 if V967000B == 1
replace margin = 17.53415 if V967000B == 2
replace margin = 2.222649 if V967000B == 4
replace margin = 16.93559 if V967000B == 5
replace margin = 12.88945 if V967000B == 6
replace margin = 1.369961 if V967000B == 8
replace margin = 18.14078 if V967000B == 9
replace margin = 15.24796 if V967000B == 10
replace margin = 75.85422 if V967000B == 11
replace margin = 5.701019 if V967000B == 12
replace margin = 1.174213 if V967000B == 13
replace margin = 25.28852 if V967000B == 15
replace margin = 18.53772 if V967000B == 16
replace margin = 17.50533 if V967000B == 17
replace margin = 5.585243 if V967000B == 18
replace margin = 10.34086 if V967000B == 19
replace margin = 18.2059 if V967000B == 20
replace margin = .9599571 if V967000B == 21
replace margin = 12.06591 if V967000B == 22
replace margin = 20.86328 if V967000B == 23
replace margin = 15.98528 if V967000B == 24
replace margin = 33.38411 if V967000B == 25
replace margin = 13.21023 if V967000B == 26
replace margin = 16.14533 if V967000B == 27
replace margin = 5.125652 if V967000B == 28
replace margin = 6.298187 if V967000B == 29
replace margin = 2.881477 if V967000B == 30
replace margin = 18.70434 if V967000B == 31
replace margin = 1.018784 if V967000B == 32
replace margin = 10.00409 if V967000B == 33
replace margin = 17.85718 if V967000B == 34
replace margin = 7.32708 if V967000B == 35
replace margin = 29.67673 if V967000B == 36
replace margin = 4.693878 if V967000B == 37
replace margin = 6.810905 if V967000B == 38
replace margin = 6.358875 if V967000B == 39
replace margin = 7.807159 if V967000B == 40
replace margin = 8.092045 if V967000B == 41
replace margin = 9.211769 if V967000B == 42
replace margin = 32.89378 if V967000B == 44
replace margin = 5.841423 if V967000B == 45
replace margin = 3.461735 if V967000B == 46
replace margin = 2.408314 if V967000B == 47
replace margin = 4.926971 if V967000B == 48
replace margin = 21.0745 if V967000B == 49
replace margin = 22.26435 if V967000B == 50
replace margin = 1.956848 if V967000B == 51
replace margin = 12.53911 if V967000B == 53
replace margin = 14.74816 if V967000B == 54
replace margin = 10.33354 if V967000B == 55
replace margin = 12.97626 if V967000B == 56


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen surveydate = mdy(V960012,V960011,inty)

format %tdMon_DD,_CCYY surveydate

gen edate = 19961105

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = (electiondate - surveydate) + 1 // Add 1 to correct for election date

* Gender

gen male = V960066

recode male (0=.)

recode male (2=0)

* Age

gen age = V960605

recode age (99=.)

replace age = . if age < 17

* Education

gen education = V960610

recode education (9=.)

* Interest for election

gen interest = V960201

replace interest = 4 - interest

* Caring about outcome (national)

gen care_whole = V960202

recode care_whole (8=.)

recode care_whole (2=0)

* Closeness of election (national)

gen closeness_whole = V960382

recode closeness_whole (0=.)
recode closeness_whole (8=.)

recode closeness_whole (1=0)
recode closeness_whole (2=1)

* Closeness of election (state)

gen closeness_state = V960384

recode closeness_state (0=.)
recode closeness_state (8=.)

recode closeness_state (1=0)
recode closeness_state (3=1)

* Party identification scale (national)

gen pidscale = V960420

recode pidscale (7=.) // Other minor party (only one respondent) recoded as missing data
recode pidscale (8=3) // Apolitical recoded as Independent
recode pidscale (9=.) // NA recoded as missing data

replace pidscale = pidscale + 1

gen pidscale_whole = 8 - pidscale

label define pidscale 1 "Strong loser PID" 2 "Weak loser PID" 3 "Leaner loser PID" 4 "No PID" 5 "Leaner winner PID" 6 "Weak winner PID" 7 "Strong winner PID"
label values pidscale_whole pidscale

* Party identification scale (state)

gen pidscale_state = pidscale if statewinner == 2
replace pidscale_state = 8 - pidscale if statewinner == 1

label values pidscale_state pidscale

* National TV news attentiveness

gen watchnattv = V960242

gen nattv = V960243

recode nattv (0=.)
recode nattv (8=.)
recode nattv (9=.)

replace nattv = 6 - nattv

replace nattv = 1 if watchnattv == 0
replace nattv = 1 if watchnattv == 8

recode nattv (.=-99)

* Local TV news attentiveness

gen watchloctv = V960244

gen loctv = V960245

recode loctv (0=.)
recode loctv (8=.)
recode loctv (9=.)

replace loctv = 6 - loctv

replace loctv = 1 if watchloctv == 0
replace loctv = 1 if watchloctv == 8

recode loctv (.=-99)

* Press news attentiveness

gen readpress = V960246

gen press = V960248

recode press (0=.)
recode press (8=.)
recode press (9=.)

replace press = 6 - press

replace press = 1 if readpress == 0
replace press = 1 if readpress == 8
replace press = 1 if V960247 == 5

recode press (.=-99)

* Magazine news attentiveness

gen readmagazines = V961333

gen magazines = V961334

recode magazines (0=.)
recode magazines (8=.)
recode magazines (9=.)

replace magazines = 6 - magazines

replace magazines = 1 if readmagazines == 5
replace magazines = 1 if readmagazines == 8

recode magazines (.=-99)

* Radio news attentiveness

gen listenradio = V961335

gen radio = V961336

recode radio (0=.)
recode radio (8=.)
recode radio (9=.)

replace radio = 6 - radio // Note: 3-point scale (rather than 5-point scale)

recode radio (1=2)
recode radio (3=4)

replace radio = 1 if listenradio == 5
replace radio = 1 if listenradio == 8

recode radio (.=-99)

* News attentiveness index

egen news = rowmax(nattv loctv press magazines radio)

recode news (-99=.)

* Al Gore - Correct answer (U.S. vice-president) = 1, Incorrect answer = 0

gen gore = V961189

recode gore (0=.)
recode gore (9=.)

recode gore (5=0)
recode gore (8=0)

* William Rehnquist - Correct answer (Supreme Court Chief Justice) = 1, Incorrect answer = 0

gen rehnquist = V961190

recode rehnquist (0=.)
recode rehnquist (9=.)

recode rehnquist (5=0)
recode rehnquist (8=0)

* Boris Yeltsin - Correct answer (President of Russia) = 1, Incorrect answer = 0

gen yeltsin = V961191

recode yeltsin (0=.)
recode yeltsin (9=.)

recode yeltsin (5=0)
recode yeltsin (8=0)

* Newt Gingrich - Correct answer (House speaker) = 1, Incorrect answer = 0

gen gingrich = V961192

recode gingrich (0=.)
recode gingrich (9=.)

recode gingrich (5=0)
recode gingrich (8=0)

* Party with the most members in the U.S. House before election - Correct answer (Republican) = 1, Incorrect answer = 0

gen house = V961072

recode house (0=.)
recode house (9=.)

recode house (1=0)
recode house (5=1)
recode house (8=0)

* Party with the most members in the U.S. Senate before election - Correct answer (Republican) = 1, Incorrect answer = 0

gen senate = V961073

recode senate (0=.)
recode senate (9=.)

recode senate (1=0)
recode senate (5=1)
recode senate (8=0)

* Political knowledge index

gen knowledge = gore + rehnquist + yeltsin + gingrich + house + senate

* Political discussion

gen discussion = V961005

recode discussion (8=.)
recode discussion (9=.)

replace discussion = 0 if V961004 == 5

gen discussion_3pts = 0 if discussion < 2 & discussion!=.
replace discussion_3pts = 1 if discussion >= 2 & discussion < 4 & discussion!=.
replace discussion_3pts = 2 if discussion >= 4 & discussion!=.


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

* Forecasts (1 = Democrat, 2 = Republican, 3 = Perot, 7 = other)

gen forecast_whole = V960381

recode forecast_whole (9=.)

* Identify correct forecasts

gen correct_whole_d = 0 if forecast_whole!=1 & forecast_whole!=.
replace correct_whole_d = 1 if forecast_whole == 1


******************************
** STATE-LEVEL EXPECTATIONS **
******************************

* Forecasts (1 = Democrat, 2 = Republican, 3 = Perot, 7 = other)

gen forecast_state = V960383

recode forecast_state (9=.)

* Identify correct forecasts

gen correct_state_d = 0 if forecast_state!=statewinner & forecast_state!=.
replace correct_state_d = 1 if forecast_state == statewinner & forecast_state!=.


**********
** SAVE **
**********

save "us1996_anes.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts (national)

logistic correct_whole_d discussion pidscale_whole interest news knowledge i.care_whole i.closeness_whole age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1

* Regression analysis and percentage of correct and incorrect forecasts (state)

melogit correct_state_d discussion pidscale_state interest news knowledge i.closeness_state age i.male education time margin || V967000B: , or
estimates table, star(.05 .01 .001)

tab correct_state_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Presidency winner (DV)"
label variable correct_state_d "State winner (DV)"
label variable discussion "Discussion"
label variable pidscale_whole "National PID"
label variable pidscale_state "State PID"
label variable interest "Interest"
label variable news "News attentiveness"
label variable knowledge "Political knowledge"
label variable care_whole "Caring about outcome"
label variable closeness_whole "Perceived closeness"
label variable closeness_state "Perceived closeness"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"
label variable margin "Margin"

quietly logistic correct_whole_d discussion pidscale_whole interest news knowledge i.care_whole i.closeness_whole age i.male education time

estpost tabstat correct_whole_d discussion pidscale_whole interest news knowledge care_whole closeness_whole age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us1996_anes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1996 American presidential election (ANES), national level") replace

eststo clear

quietly melogit correct_state_d discussion pidscale_state interest news knowledge i.closeness_state age i.male education time margin || V967000B: , or

estpost tabstat correct_state_d discussion pidscale_state interest news knowledge closeness_state age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us1996_anes_summary_state.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1996 American presidential election (ANES), state level") replace

eststo clear

log close